package cc.dong.dao.impl;

import cc.dong.dao.BaseDao;
import cc.dong.dao.EmployeeDao;
import cc.dong.entity.Employee;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author xiaoDong
 * @version 1.0.0
 * @ClassName EmployeeDaoImpl.java
 * @Description TODO
 * @createTime 2024年05月30日 09:24:00
 */
public class EmployeeDaoImpl extends BaseDao implements EmployeeDao {
    @Override
    public Employee login(String employeeNo, String password) {
        //sql指令
        String sql = "SELECT * FROM employee WHERE employeeNo =? AND `password` =? and dimission = 1";

        ResultSet rs = executeQuery(sql, employeeNo, password);
        if (rs != null) {
            try {
                while (rs.next()) {
                    Employee employee = new Employee();
                    employee.setId(rs.getInt("id"));
                    employee.setEmployeeNo(rs.getString("employeeNo"));
                    employee.setName(rs.getString("name"));
                    employee.setImgPath(rs.getString("imgPath"));
                    employee.setSex(rs.getString("sex"));
                    employee.setBirthday(rs.getDate("birthday"));
                    employee.setDepId(rs.getInt("depId"));
                    employee.setPositionId(rs.getInt("positionId"));
                    employee.setPhone(rs.getString("phone"));
                    employee.setEntryDate(rs.getDate("entryDate"));
                    employee.setEmail(rs.getString("email"));
                    employee.setDimission(rs.getInt("dimission"));
                    return employee;


                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                closedAll(rs);
            }


        }


        return null;
    }
}
